<?php
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
/**
 * Created by PhpStorm.
 * User: 张
 * Date: 2015/10/25
 * Time: 19:05
 */
?>
<?= '<link rel="stylesheet" type="text/css" href="./ass/p/category/category.css?v='.date('Ymt').'"/>' ;?>
<div class="content">
    <div class="parent-box">
        <div class="box-head">
            主分类
        </div>
        <div>
            <ul id="parent">
                <?php if(!empty($cid)):?>
                    <?php foreach($cid as $k=>$v):?>
                        <li class="<?= ($v['cid']==$click)? 'parent-click' :'';?>">
                            <a href="<?= Url::to(['/articlect/index','cid'=>$v['cid']]);?>"><?= $v['name']?></a>
                        </li>
                    <?php endforeach;?>
                <?php endif;?>
            </ul>
        </div>
    </div>
    <div class="list-box">
        <div class="box-head">
            <span class="width6">排序</span>
            <span class="width14">分类名称</span>
            <span class="width20">操作</span>
            <span class="width20 float-r align-r">批量
                <select class="input-select">
                    <option value="-1" selected = "selected" >选择</option>
                    <?php if(!empty($cid)):?>
                        <?php foreach($cid as $k=>$v):?>
                            <option value="<?= $v['cid'];?>"><?= $v['name']?></option>
                        <?php endforeach;?>
                    <?php endif;?>
                    <option value="0">删除</option>
                </select>
            </span>
        </div>
        <ul id="list">
            <?php if(!empty($articlectModel['model'])):?>
                <?php foreach($articlectModel['model'] as $k=>$v):?>
                    <li>
                        <p class="width6"><?= $k+($articlectModel['nowpage']-1)*$articlectModel['limits']+1; ?></p>
                        <p class="width14"><?= $v['name']; ?></p>
                        <p class="width20">
                            <a class="delete-one" href="<?= Url::to(['/articlect/deleteone','cid'=>$v['cid'],'parent_cid'=>$v['parent_cid']]); ?>"><i class="icon-trash icon-large"></i></a>
                            <a class="update-one" rel="<?= $v['name']; ?>" name="<?= $v['cid']?>" href="javascript:void(0);"><i class="icon-edit icon-large"></i></a>
                        </p>
                        <p class="width9 checkbox checkbox-off float-r">
                            <input type="hidden" name="<?= $v['cid'];?>" value="0">
                        </p>
                    </li>
                <?php endforeach;?>
            <?php endif;?>
        </ul>
        <div class="box-footer">
            <ul class="page float-l">
                <li><a href="<?= Url::to(['/articlect/index','page'=>$articlectModel['backpage'],'cid'=>$articlectModel['parent_cid']]); ?>"><i class="icon-angle-left"></i></a></li>
                <?php for($i=1 ; $i<=$articlectModel['page'] ; $i++):?>
                    <?php if($articlectModel['nowpage']==$i):?>
                        <li><a href="<?= Url::to(['/articlect/index','page'=>$i,'cid'=>$articlectModel['parent_cid']]); ?>" class="page-o"><?= $i;?></a></li>
                    <?php else:?>
                        <li><a href="<?= Url::to(['/articlect/index','page'=>$i,'cid'=>$articlectModel['parent_cid']]); ?>" class="page-n"><?= $i;?></a></li>
                    <?php endif?>
                <?php endfor;?>
                <li><a href="<?= Url::to(['/articlect/index','page'=>$articlectModel['frontpage'],'cid'=>$articlectModel['parent_cid']]); ?>"><i class="icon-angle-right"></i></a></li>
            </ul>
            <div class="box-footer-button">
                <a href="javascript:void(0)" id="delete" class="update-action"><i class="icon-random"><br/><span>批量操作</span></i></a>
                <span class="red hint"></span>
            </div>
        </div>
        <div class="oneupdate" style="display:none">
            <div style="float: left;">
                <?php $form=ActiveForm::begin([
                    'enableClientValidation'=>true,
                    'method'=>'post',
                    'action'=>['/articlect/updateone'],
                    'fieldConfig'=>[
                        'template' => "{label}{input}{error}",
                        'labelOptions' => ['class' => 'col-lg-2 control-label'],
                    ],
                ]);
                ?>
                <?= $form->field($model,'cid')
                    ->hiddenInput(['class'=>'cid'])
                    ->label(false)
                    ->error(false);
                ?>
                <?= $form->field($model,'name')
                    ->textInput(['class'=>'add-text'])
                    ->label('修改分类：');
                ?></div>
            <div style="float: left;padding-left:15px;"><?= Html::submitButton('修改',['class'=>'addsubmit'])?></div>
            <?php ActiveForm::end();?>
        </div>
    </div>
    <div class="editor-box">
        <div class="box-head">
            <span class="width20">添加分类</span>
        </div>
        <div class="add">
            <?php $form=ActiveForm::begin([
                'enableClientValidation'=>true,//是否启用客户端验证
                'method'=>'post',
                'action'=>['/articlect/add'],
                'fieldConfig'=>[
                    'template' => "{label}{input}{error}",
                    'labelOptions' => ['class' => 'col-lg-2 control-label'],
                ],
            ])?>
                <?= $form->field($model,'parent_cid')
                    ->hiddenInput(['readonly'=>'readonly','value'=>$click])
                    ->label(false)
                    ->error(false)
                ?>
                <?= $form->field($model,'name')
                    ->textInput(['class'=>'input-text','placeholder'=>'请输入分类名称'])
                    ->label(false);
                ?>
                <?= Html::submitButton('添加',['class'=>'submit'])?>
            <?php ActiveForm::end();?>
        </div>


    </div>
</div>
<script>
    //单条数据修改
    $('.update-one').click(function(){
        $('.cid').val($(this).attr('name'));
        $('.add-text').val($(this).attr('rel'));
        $('.oneupdate').css('display','block')
    });
    //父级类别选中状态
    $('#parent li').on('click',function(){
        $('#parent li').removeClass('parent-click');
        $(this).addClass('parent-click');
    });
</script>
